﻿using System.Collections.Generic;
using System.Data.Common;
using SmallDataBase.DTO;

namespace SmallDataBase
{
    public interface ISQLBuilder
    {
        #region insert

        /// <summary>
        /// 生成插入SQL语句
        /// </summary>
        /// <param name="dto">元对象</param>
        /// <returns>插入SQL语句</returns>
        string BuildInsertSQL(MetaDTO dto);
        /// <summary>
        /// 生成插入SQL语句
        /// </summary>
        /// <param name="dto">元对象</param>
        /// <returns>插入SQL语句</returns>
        string BuildInsertSQLAndReturnLastInsertID(MetaDTO dto);

        #endregion

        #region update

        /// <summary>
        /// 生成更新SQL语句
        /// </summary>
        /// <param name="dto">元对象</param>
        /// <returns>更新SQL语句</returns>
        string BuildUpdateSQL(MetaDTO dto);

        #endregion

        #region delete

        /// <summary>
        /// 生成删除SQL语句
        /// </summary>
        /// <param name="dto">元对象</param>
        /// <param name="queryObj">条件对象</param>
        /// <returns>删除SQL语句</returns>
        string BuildDeleteSQL(MetaDTO dto, MetaDTO queryObj);
        /// <summary>
        /// 生成删除SQL语句
        /// </summary>
        /// <param name="dto">元对象</param>
        /// <param name="queryObj">条件对象</param>
        /// <returns>删除SQL语句</returns>
        string BuildDeleteSQL(MetaDTO dto, params SQLQueryGroupDTO[] queryObj);

        #endregion

        #region select

        /// <summary>
        /// 生成查询SQL语句
        /// </summary>
        /// <param name="dto">元对象</param>
        /// <returns>查询SQL语句</returns>
        string BuildSeletSQL(MetaDTO dto);

        /// <summary>
        /// 生成查询SQL语句
        /// </summary>
        /// <param name="dto">元对象</param>
        /// <param name="queryObj">条件对象</param>
        /// <returns>查询SQL语句</returns>
        string BuildSeletSQL(MetaDTO dto, MetaDTO queryObj);
        /// <summary>
        /// 生成查询SQL语句
        /// </summary>
        /// <param name="dto">元对象</param>
        /// <param name="queryObj">条件对象</param>
        /// <returns>查询SQL语句</returns>
        string BuildSeletSQL(MetaDTO dto, params SQLQueryGroupDTO[] queryObj);

        #endregion
        /// <summary>
        /// 生成sql参数
        /// </summary>
        /// <param name="dto">元数据</param>
        /// <returns>sql参数对象集合</returns>
        IEnumerable<DbParameter> BuildParameter(MetaDTO dto);
        IEnumerable<DbParameter> BuildParameter(SQLQueryGroupDTO dto);

        /// <summary>
        /// 获取command对象
        /// </summary>
        /// <returns>command对象</returns>
        DbCommand BuildCommand();

        /// <summary>
        /// 获取连接对象
        /// </summary>
        /// <param name="config">配置对象</param>
        /// <returns>连接对象</returns>
        DbConnection BuildConnection(ConfigDTO config);
    }
}